package com.openbravo.data.gui;

import com.openbravo.data.loader.LocalRes;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class JMessageDialog extends JDialog
{
  private JPanel jPanel2;
  private JPanel jPanel3;
  private JPanel jPanel4;
  private JButton jcmdMore;
  private JButton jcmdOK;
  private JLabel jlblErrorCode;
  private JLabel jlblIcon;
  private JLabel jlblMessage;
  private JScrollPane jscrException;
  private JTextArea jtxtException;

  private JMessageDialog(Frame paramFrame, boolean paramBoolean)
  {
    super(paramFrame, paramBoolean);
  }

  private JMessageDialog(Dialog paramDialog, boolean paramBoolean)
  {
    super(paramDialog, paramBoolean);
  }

  private static Window getWindow(Component paramComponent)
  {
    if (paramComponent == null)
      return new JFrame();
    if (((paramComponent instanceof Frame)) || ((paramComponent instanceof Dialog)))
      return (Window)paramComponent;
    return getWindow(paramComponent.getParent());
  }

  public static void showMessage(Component paramComponent, MessageInf paramMessageInf)
  {
    Window localWindow = getWindow(paramComponent);
    JMessageDialog localJMessageDialog;
    if ((localWindow instanceof Frame))
      localJMessageDialog = new JMessageDialog((Frame)localWindow, true);
    else
      localJMessageDialog = new JMessageDialog((Dialog)localWindow, true);
    localJMessageDialog.initComponents();
    localJMessageDialog.applyComponentOrientation(paramComponent.getComponentOrientation());
    localJMessageDialog.jscrException.setVisible(false);
    localJMessageDialog.getRootPane().setDefaultButton(localJMessageDialog.jcmdOK);
    localJMessageDialog.jlblIcon.setIcon(paramMessageInf.getSignalWordIcon());
    localJMessageDialog.jlblErrorCode.setText(paramMessageInf.getErrorCodeMsg());
    localJMessageDialog.jlblMessage.setText("<html>" + paramMessageInf.getMessageMsg());
    if (paramMessageInf.getCause() == null)
    {
      localJMessageDialog.jtxtException.setText(null);
    }
    else
    {
      StringBuffer localStringBuffer = new StringBuffer();
      Object localObject;
      if ((paramMessageInf.getCause() instanceof Throwable))
      {
        for (localObject = (Throwable)paramMessageInf.getCause(); localObject != null; localObject = ((Throwable)localObject).getCause())
        {
          localStringBuffer.append(localObject.getClass().getName());
          localStringBuffer.append(": \n");
          localStringBuffer.append(((Throwable)localObject).getMessage());
          localStringBuffer.append("\n\n");
        }
      }
      else
      {
        int i;
        if ((paramMessageInf.getCause() instanceof Throwable[]))
        {
        	    localObject =  (Throwable[])paramMessageInf.getCause();
        	    Throwable[] localObject2=(Throwable[]) localObject;
          for (i = 0; i < localObject2.length; i++)
          {
            localStringBuffer.append(localObject2[i].getClass().getName());
            localStringBuffer.append(": \n");
            localStringBuffer.append(localObject2[i].getMessage());
            localStringBuffer.append("\n\n");
          }
        }
        else if ((paramMessageInf.getCause() instanceof Object[]))
        {
          localObject = (Object[])paramMessageInf.getCause();
          Object[] localObject2=(Object[]) localObject;
          
          for (i = 0; i < localObject2.length; i++)
          {
            localStringBuffer.append(localObject2[i].toString());
            localStringBuffer.append("\n\n");
          }
        }
        else if ((paramMessageInf.getCause() instanceof String))
        {
          localStringBuffer.append(paramMessageInf.getCause().toString());
        }
        else
        {
          localStringBuffer.append(paramMessageInf.getCause().getClass().getName());
          localStringBuffer.append(": \n");
          localStringBuffer.append(paramMessageInf.getCause().toString());
        }
      }
      localJMessageDialog.jtxtException.setText(localStringBuffer.toString());
    }
    localJMessageDialog.jtxtException.setCaretPosition(0);
    localJMessageDialog.setVisible(true);
  }

  private void initComponents()
  {
    this.jPanel4 = new JPanel();
    this.jlblErrorCode = new JLabel();
    this.jlblMessage = new JLabel();
    this.jscrException = new JScrollPane();
    this.jtxtException = new JTextArea();
    this.jlblIcon = new JLabel();
    this.jPanel3 = new JPanel();
    this.jPanel2 = new JPanel();
    this.jcmdOK = new JButton();
    this.jcmdMore = new JButton();
    setTitle(LocalRes.getIntString("title.message"));
    setResizable(false);
    addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent paramWindowEvent)
      {
        JMessageDialog.this.closeDialog(paramWindowEvent);
      }
    });
    this.jPanel4.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanel4.setLayout(new BoxLayout(this.jPanel4, 1));
    this.jlblErrorCode.setFont(this.jlblErrorCode.getFont().deriveFont(this.jlblErrorCode.getFont().getStyle() & 0xFFFFFFFE, this.jlblErrorCode.getFont().getSize() - 2));
    this.jlblErrorCode.setText("jlblErrorCode");
    this.jPanel4.add(this.jlblErrorCode);
    this.jlblMessage.setText("jlblMessage");
    this.jlblMessage.setVerticalAlignment(1);
    this.jlblMessage.setMinimumSize(new Dimension(200, 100));
    this.jlblMessage.setPreferredSize(new Dimension(200, 100));
    this.jPanel4.add(this.jlblMessage);
    this.jscrException.setAlignmentX(0.0F);
    this.jtxtException.setEditable(false);
    this.jscrException.setViewportView(this.jtxtException);
    this.jPanel4.add(this.jscrException);
    getContentPane().add(this.jPanel4, "Center");
    this.jlblIcon.setVerticalAlignment(1);
    this.jlblIcon.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    getContentPane().add(this.jlblIcon, "Before");
    this.jPanel3.setLayout(new BorderLayout());
    this.jcmdOK.setText(LocalRes.getIntString("button.ok"));
    this.jcmdOK.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JMessageDialog.this.jcmdOKActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdOK);
    this.jcmdMore.setText(LocalRes.getIntString("button.information"));
    this.jcmdMore.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JMessageDialog.this.jcmdMoreActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdMore);
    this.jPanel3.add(this.jPanel2, "After");
    getContentPane().add(this.jPanel3, "South");
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((localDimension.width - 455) / 2, (localDimension.height - 171) / 2, 455, 171);
  }

  private void jcmdMoreActionPerformed(ActionEvent paramActionEvent)
  {
    this.jcmdMore.setEnabled(false);
    this.jscrException.setVisible(true);
    setSize(getWidth(), 310);
    validateTree();
  }

  private void jcmdOKActionPerformed(ActionEvent paramActionEvent)
  {
    setVisible(false);
    dispose();
  }

  private void closeDialog(WindowEvent paramWindowEvent)
  {
    setVisible(false);
    dispose();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.gui.JMessageDialog
 * JD-Core Version:    0.6.0
 */